<?php
class ome_ctl_admin_setting extends desktop_controller{
    var $name = "基本设置";
    var $workground = "setting_tools";

    public function index(){
        if($_POST['set']){
            $settins = $_POST['set'];
            foreach($settins as $set=>$value){
                $curSet = $this->app->getConf($set);
                if($curSet!=$settins[$set]){
                    $curSet = $settins[$set];
                    $this->app->setConf($set,$settins[$set]);
                }
            }
        }
        $setView = array();
        foreach(kernel::servicelist('system_setting') as $k=>$obj){
            if(method_exists($obj,'view')){
                $setView[] = $obj->view();
            }
        }
        $this->pagedata['setView']=$setView;
        $this->page("admin/system/setting_index.html");
    }

     /*
     * 订单异常类型设置
     */
    function abnormal(){
        $this->finder('ome_mdl_abnormal_type',array(
            'title'=>'订单异常类型设置',
            'actions'=>array(
                          array('label'=>'添加','href'=>'index.php?app=ome&ctl=admin_setting&act=addabnormal','target'=>'_blank'),
                        ),
            'use_buildin_new_dialog' => false,
            'use_buildin_set_tag'=>false,
            'use_buildin_recycle'=>false,
            'use_buildin_export'=>false,
            'use_buildin_import'=>false,
         ));
    }
    /*
    * 添加订单异常类型
    */
    function addabnormal(){
        $oAbnormal = &$this->app->model("abnormal_type");
        if($_POST){
            $this->begin('index.php?app=ome&ctl=admin_setting&act=abnormal');
            $oAbnormal->save($_POST['type']);
            $this->end(true, app::get('base')->_('保存成功'));
        }
		$this->pagedata['title'] = '添加订单异常类型';
        $this->singlepage("admin/system/abnormal.html");
    }
    /*
    * 编辑订单异常类型
    */
    function editabnormal($type_id){
        $oAbnormal = &$this->app->model("abnormal_type");
        $this->pagedata['abnormal']=$oAbnormal->dump($type_id);
		$this->pagedata['title'] = '编辑订单异常类型';
        $this->singlepage("admin/system/abnormal.html");
    }
     /*
     * 售后问题类型设置
     */
    function product_problem(){//return_product_problem
        $this->finder('ome_mdl_return_product_problem',array(
            'title'=>'售后问题类型设置',
            'actions'=>array(
                          array('label'=>'添加','href'=>'index.php?app=ome&ctl=admin_setting&act=addproblem'),
                        ),
            'use_buildin_new_dialog' => false,
            'use_buildin_set_tag'=>false,
            'use_buildin_recycle'=>false,
            'use_buildin_export'=>false,
            'use_buildin_import'=>false,
         ));
    }

    /*
     * 添加售后问题
     */
    function addproblem(){
        $oProblem = &$this->app->model("return_product_problem");
        if($_POST){
            $this->begin('index.php?app=ome&ctl=admin_setting&act=product_problem');
            $oProblem->save($_POST);
            $this->end(true, app::get('base')->_('保存成功'));
        }
        $this->page("admin/system/product_problem.html");
    }
    /*
     * 编辑售后问题
     */
    function editproblem($problem_id){
        $oProblem = &$this->app->model("return_product_problem");
        $problem = $oProblem->dump($problem_id);
        $this->pagedata['problem'] = $problem;
        $this->page("admin/system/product_problem.html");
    }

    /*
     * 售后问题类型列表   树状结构
     * problem_cat
     */
    /*function problem_cat(){
        header("Cache-Control:no-store, no-cache, must-revalidate"); // HTTP/1.1
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");// 强制查询etag
        header('Progma: no-cache');
        $objCat = &app::get('ome')->model('return_product_problem');
        if($objCat->checkTreeSize()){
            $this->pagedata['hidenplus']=true;
        }
        $tree=$objCat->get_cat_list();
        $this->pagedata['tree_number']=count($tree);
        if($tree){
            foreach($tree as $k=>$v){
                $tree[$k]['link'] = array('problem_id'=>array(
                                'v'=>$v['problem_id'],
                                't'=>app::get('base')->_('售后类型').app::get('base')->_('是').$v['cat_name']
                            ));
            }
        }
        $this->pagedata['tree']= &$tree;
        $depath=array_fill(0,$objCat->get_cat_depth(),'1');
        $this->pagedata['depath']=$depath;
        $this->page('admin/return_product/problem/map.html');
    }*/

    /*
     * 添加售后问题
     */
    function addnew($nCatId = 0){
        $this->_add_problem($nCatId);
    }
    function _add_problem($id=0,$type='add'){

        $objCat = &app::get('ome')->model('return_product_problem');
        $catList =$objCat->getMapTree(0,'');
        $aCatNull[] = array('problem_id'=>0,'cat_name'=>app::get('base')->_('----无----'),'step'=>1);
        if(empty($catList)){
            $catList = $aCatNull;
        }else{
            $catList = array_merge($aCatNull, $catList);
        }
        $this->pagedata['catList'] = $catList;

            $aCat = $objCat->dump($id);
            $this->pagedata['cat']['parent_id'] = $aCat['problem_id'];
            if($type == 'edit'){
                $this->pagedata['cat']['problem_id'] = $aCat['problem_id'];
                $this->pagedata['cat']['cat_name'] = $aCat['cat_name'];
                $this->pagedata['cat']['parent_id'] = $aCat['parent_id'];
                $this->pagedata['cat']['p_order'] = $aCat['p_order'];
            }
        $this->page("admin/return_product/problem/add_problem.html");
    }

    function problem_save(){
        $this->begin('index.php?app=ome&ctl=admin_setting&act=problem_cat');
        $objCat = &app::get('ome')->model('return_product_problem');
        if($objCat->save($_POST['cat']))
            $this->end(true,'保存成功');
        else
            $this->end(false,'保存失败');
    }

    function toRemove($nCatId){
        $this->begin('index.php?app=ome&ctl=admin_setting&act=problem_cat');
        $objCat = &app::get('ome')->model('return_product_problem');
        $cat_sdf = $objCat->dump($nCatId);

        if($objCat->toRemove($nCatId)){
            $this->end(true,$cat_sdf['cat_name'].app::get('base')->_('已删除'));

        }
        $this->end(false,app::get('base')->_('删除失败：本分类下还有子分类'));
    }

    function edit($nCatId){
        $this->_add_problem($nCatId,'edit');
    }

    function getByStr(){
        header('Content-type: application/json');

        $objCat = &app::get('ome')->model('return_product_problem');

        $data = $objCat->getCatLikeStr($_POST['kw']);

        echo $data;
    }
    /*
     * 更新排序 updateSort
     */
    function updateSort(){
        $this->begin('index.php?app=ome&ctl=admin_setting&act=problem_cat');
        $objCat = &app::get('ome')->model('return_product_problem');
        $objCat->updateSort($_POST['p_order']);
        $this->end(true,app::get('base')->_('保存成功'),'index.php?app=ome&ctl=admin_setting&act=problem_cat');
    }

}
?>
